/**
 * 
 */
package unseen.games.ui.adapter;

import java.util.List;

import unseen.games.model.Score;
import unseen.games.taptap.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author PERRAUDIN Steven <sperraudin@neotilus.com>
 *
 * @date 15 juin 2010
 */
public class HighScoreAdapter extends BaseAdapter {

	public List<Score> mList;
	protected Context mContext;
	protected int mnViewResId;
	protected LayoutInflater mInflater;
	
		
	public HighScoreAdapter(Context context, int resId, List<Score> list){
		super();
		mInflater 	= LayoutInflater.from(context);
		mContext 	= context;
		mList 		= list;
		mnViewResId = resId;
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Score getItem(int position) {
		return (Score)mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	static class ScoreViewHolder
	{
		TextView userName;
		TextView score;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ScoreViewHolder holder 	= null;
		
		if(convertView == null){		
			convertView 		= mInflater.inflate(mnViewResId, null);
			holder 				= new ScoreViewHolder();
			
			holder.userName 	= (TextView) convertView.findViewById (R.id.list_item_username);
			holder.score		= (TextView) convertView.findViewById (R.id.list_item_score);
			
			convertView.setTag(holder);
		}
		else{
			holder = (ScoreViewHolder) convertView.getTag();
		}
		
		holder.userName.setText(getItem(position).getUsername());
		holder.score.setText("" + getItem(position).getScore());
		
		return convertView;
	}

	/**
	 * @return the mList
	 */
	public List<Score> getmList() {
		return mList;
	}

	public void setList(List<Score> scores) {
		mList = scores;		
	}

}
